package com.yt.calendar.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yt.calendar.dto.PlanDto;
import com.yt.calendar.entity.Plan;
import com.yt.calendar.mapper.PlanMapper;
import com.yt.calendar.service.IPlanService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yt
 * @since 2021-07-16
 */
@Service
public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements IPlanService {
    @Resource
    private PlanMapper planMapper;

    @Override
    public boolean updateByDto(PlanDto planDto) {
        UpdateWrapper<Plan> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("title", planDto.getTitle()).eq("id", planDto.getPlanId());
        return this.update(updateWrapper);
    }

    @Override
    public boolean deleteUnusedPlan(int planId) {
        return planMapper.updateToDelete(planId) > 0;
    }
}
